function Refluxive(){
	
    this.gameName = 'refluxive';
	this.bouncies = [];
	this.paddle = new PaddleDesc();
	this.gameImages = [];
	
	this.init = function() {
		loadGameImage('background');
		loadGameImage('bouncy1');
		loadGameImage('bouncy2');
		loadGameImage('bouncy3');
		loadGameImage('paddle');
		loadGameImage('gameOver');
		blit(this.gameImages['background'], 0, 0);
		// N ↑ S ↓ W ← E →
		this.bouncies.push(new BouncyDesc(jshen.math.randomInteger(1, 180), 30, 'NW'));
		this.bouncies.push(new BouncyDesc(jshen.math.randomInteger(1, 180), 10, 'NE'));
		this.bouncies.push(new BouncyDesc(jshen.math.randomInteger(1, 180), 20, 'SE'));
	}
	
	this.destroy = function() {
		// TODO
	}
	
	this.processFrame = function() {
		if (!this.bouncies[0].onScreen
				&& !this.bouncies[1].onScreen
				&& !this.bouncies[2].onScreen) {
			blit(this.gameImages['gameOver'], 10, 40);
			return;
		}
		var i;
		for (i=0; i<3; i++) {
			if (this.bouncies[i].onScreen) {
				blit(this.gameImages['bouncy' + (i+1)], this.bouncies[i].x, this.bouncies[i].y);
				switch (this.bouncies[i].dir) {
					case 'NW':
						this.bouncies[i].x -= 3;
						this.bouncies[i].y -= 3;
						break;
					case 'NE':
						this.bouncies[i].x += 3;
						this.bouncies[i].y -= 3;
						break;
					case 'SW':
						this.bouncies[i].x -= 3;
						this.bouncies[i].y += 3;
						break;
					case 'SE':
						this.bouncies[i].x += 3;
						this.bouncies[i].y += 3;
						break;
				}
			}
		}
		for (i=0; i<3; i++) {
			if (this.bouncies[i].onScreen) {
				if (this.bouncies[i].x < 1) {
					if (this.bouncies[i].dir === 'NW') {
						this.bouncies[i].dir = 'NE';
					} else { // SW
						this.bouncies[i].dir = 'SE';
					}
				} else if (this.bouncies[i].x > 174) {
					if (this.bouncies[i].dir === 'NE') {
						this.bouncies[i].dir = 'NW';
					} else { // SE
						this.bouncies[i].dir = 'SW';
					}
				}
				if (this.bouncies[i].y < 1) {
					if (this.bouncies[i].dir === 'NW') {
						this.bouncies[i].dir = 'SW';
					} else { // NE
						this.bouncies[i].dir = 'SE';
					}
				} else if (this.bouncies[i].y > 210) {
					this.bouncies[i].onScreen = false;
				} else {
					if (detectCollision(this.paddle, this.bouncies[i])) {
						if (this.bouncies[i].dir === 'SW') {
							this.bouncies[i].dir = 'NW';
						} else {
							this.bouncies[i].dir = 'NE';
						}
						addToScore(10);
					}
				}
			}			
		}
		if (gameState.playerDirectionRight) {
			this.paddle.x += 4;
			if (this.paddle.x > 174) {
				this.paddle.x = 174;
			}
		} else if (gameState.playerDirectionLeft) {
			this.paddle.x -= 4;
			if (this.paddle.x < 1) {
				this.paddle.x = 1;
			}
		}
		blit(this.gameImages['paddle'], this.paddle.x, this.paddle.y);
	}

    function BouncyDesc(inX, inY, inDir){
        this.x = inX;
        this.y = inY;
        this.width = 18;
        this.height = 18;
        this.dir = inDir;
        this.onScreen = true;
    }

    function PaddleDesc(){
        this.x = 88;
        this.y = 188;
        this.width = 24;
        this.height = 10;
    }
}

Refluxive.prototype = new MiniGame;
